@use plume_models::instance::Instance;
@use validator::ValidationErrors;
@use crate::templates::{base, instance::admin_header};
@use crate::template_utils::*;
@use crate::routes::instance::InstanceSettingsForm;
@use crate::routes::*;

@(ctx: BaseContext, instance: Instance, form: InstanceSettingsForm, errors: ValidationErrors)

@:base(ctx, i18n!(ctx.1, "Administration of {0}"; instance.name.clone()), {}, {}, {
  @:admin_header(ctx, "Administration", 1)

  <form method="post" action="@uri!(instance::update_settings)">
    @(Input::new("name", i18n!(ctx.1, "Name"))
        .default(&form.name)
        .error(&errors)
        .set_prop("minlength", 1)
        .html(ctx.1))

    <label for="open_registrations">
      <input type="checkbox" name="open_registrations" id="open_registrations" @if instance.open_registrations { checked }>
      @i18n!(ctx.1, "Allow anyone to register here")
    </label>

      <label for="short_description">@i18n!(ctx.1, "Short description")<small>@i18n!(ctx.1, "Markdown syntax is supported")</small></label>
      <textarea id="short_description" name="short_description">@Html(form.short_description)</textarea>

      <label for="long_description">@i18n!(ctx.1, "Long description")<small>@i18n!(ctx.1, "Markdown syntax is supported")</small></label>
      <textarea id="long_description" name="long_description">@Html(form.long_description)</textarea>

      @(Input::new("default_license", i18n!(ctx.1, "Default article license"))
        .default(&form.default_license)
        .error(&errors)
        .set_prop("minlength", 1)
        .html(ctx.1))

      <input type="submit" value="@i18n!(ctx.1, "Save these settings")"/>
  </form>
})
